package io.github.zerobyteword.metricspringstartup;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationRunListener;
import org.springframework.context.ConfigurableApplicationContext;

import java.time.Duration;
import java.util.Comparator;


public class MetricSpringApplicationRunListener implements SpringApplicationRunListener {
    private MetricApplicationStartup metricApplicationStartup;

    public MetricSpringApplicationRunListener(SpringApplication application, String[] args) {
        this.metricApplicationStartup = new MetricApplicationStartup();
        application.setApplicationStartup(metricApplicationStartup);
    }

    @Override
    public void ready(ConfigurableApplicationContext context, Duration timeTaken) {
        SpringApplicationRunListener.super.ready(context, timeTaken);
        metricApplicationStartup.printStartUpTimeCost();
    }
}
